import Vue from 'vue';
import './style.scss';
import tpl from './tpl.html';
import modal from '../../../../../../grsc-base/component/Modal.vue';
import Popover from '../../../../../../grsc-base/component/Popover.vue';
import Pager from '../../../../../../grsc-base/component/Pager.vue';
import service from '../service';
import lang from '../lang';
export default Vue.extend({
  i18n:{
    messages:lang
  },
  template: tpl,
  components: {
    modal,
    Popover,
    Pager
  },
  props: ['item'],
  data() {
    return {
      list:[
          {name:'uid',value:''},
          {name:'userName',value:''},
          {name:'email',value:''},
          {name:'memberType',value:''},
          {name:'lowerMemberPerson',value:''},
          {name:'invitedPerson',value:''},
          {name:'teamAllTradeProfit',value:''},
          {name:'teamPositionProfit',value:''},
      ],
        lowList:[
            {name:'uid',value:''},
            {name:'userName',value:''},
            {name:'email',value:''},
            {name:'invitedPerson',value:''},
            {name:'userAllTradeProfit',value:''},
            {name:'teamPositionProfit',value:''},
        ],
        inList:[
            {name:'uid',value:''},
            {name:'userName',value:''},
            {name:'email',value:''},
            {name:'userAllTradeProfit',value:''},
            {name:'userPositionProfit',value:''},
        ],
        lowDate:{
            startTime:'',
            endTime:'',
        },

        inDate:{
            startTime:'',
            endTime:'',
        },

        lowPage: {
            //当前页
            pageNo:null,
            //当前条数
            pageSize:null,
            //总页数
            pageNum:null,
        },

        inPage: {
            //当前页
            pageNo:null,
            //当前条数
            pageSize:null,
            //总页数
            pageNum:null,
        },
        lowListArr: [],
        inListArr:[],
    }
  },
  created() {

    for(let i of this.list){
      i.value = this.item[i.name];
      if(i.name == 'memberType'){
        i.value = this.item[i.name] == 'VIP2' ? '二级代理' : '三级代理' ;
      }
    }

    this.lowSeleDate();
    this.inSeleDate()
  },

  methods: {
    //隐藏弹窗
    hide() {
      this.$emit('hide')
    },

    //按日期查询下级
    lowSeleDate() {
        let lowData={
            uid:this.item.uid,
            startTime:this.lowDate.startTime,
            endTime:this.lowDate.endTime,
            pageNo:this.lowPage.pageNo || 1,
            pageSize:this.lowPage.pageSize || 5,

        };

        service.getUserLowerInfo(lowData).done(data=>{
            // console.log('下级',data);
            if(data.data.list!=''){
                this.lowListArr = data.data.list;
                for(let i in this.lowPage){
                    this.lowPage[i]=data.data[i]
                }
            }else{
                return
            }
        });
    },

    //按日期查询邀请
    inSeleDate(){
        let inData={
            uid:this.item.uid,
            startTime:this.inDate.startTime,
            endTime:this.inDate.endTime,
            pageNo:this.inPage.pageNo || 1,
            pageSize:this.inPage.pageSize || 5,
        }

        service.getUserTeamDto(inData).done(data=>{
            // console.log('邀请',data);
            if(data.data.list!=''){
                this.inListArr=data.data.list;
                for(let i in this.lowPage){
                    this.lowPage[i]=data.data[i]
                }
            }else{
                return
            }

        });
    },


      lowChangePage(currentPage) {
          this.lowPage.pageNo = currentPage;
          this.lowSeleDate();
      },


      inChangePage(currentPage) {
          this.inPage.pageNo = currentPage;
          this.inSeleDate();
      },
  }
})